{extend name="./template/default/m/pub/base.html" /}
{block name="seo"}
<title>个人中心-{$site_name}</title>
{/block}
{block name="content"}
{include file="./template/default/m/pub/top3.html" /}
<div class="line-container">
    <input id="nick_name" type="text" placeholder="请输入昵称（昵称为2-8个字符 ，不允许为空）"
    value="{$user.nick_name}" autocomplete="off">
</div>
<a href="javascript:void(0);" class="line-container-btn" id="btnsave">保存</a>
<div class="toast" style="display: none;"></div>
<script>

    $('#btnsave').click(function () {
        var nickname = filterStr($('#nick_name').val());
        if (nickname.length > 12){
            ShowDialog("昵称不能太长");
            return;
        }
        $.post({
            url:'/userinfo',
            data:{nickname: nickname},
            success:function (res) {
                ShowDialog(res.msg);
                setTimeout(function () {
                    location.reload();
                },1000);
            },
            error:function (data) {
                ShowDialog(data);
            }
        })
    })

    function filterStr(str)
    {
        var pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？%+_]");
        var specialStr = "";
        for(var i=0;i<str.length;i++)
        {
            specialStr += str.substr(i, 1).replace(pattern, '');
        }
        return specialStr;
    }
</script>
{/block}